package joe.beer;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class ViewBeersActivity extends Activity {

	MySQLiteHelper dbHelper;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.viewbeer);
		dbHelper = new MySQLiteHelper(this);

		ArrayList<String> test = dbHelper.getAllBeers();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, test);
		ListView lv = (ListView) findViewById(R.id.listView1);
		lv.setAdapter(adapter);

		Button b = (Button) findViewById(R.id.button1);
		b.setOnClickListener(buttonHandler);
	}

	// Create an anonymous implementation of OnClickListener
	private OnClickListener buttonHandler = new OnClickListener() {
		public void onClick(View v) {
			finish();
		}
	};

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (dbHelper != null) {
			dbHelper.close();
		}
	}
}
